using AjeeleeCms.Core.Common;
using AjeeleeCms.Web.Plugin.Feedback.BLL;
using AjeeleeCms.Web.UI;
using System;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
namespace AjeeleeCms.Web.Plugin.Feedback.admin
{
	public class index : ManagePage
	{
		protected HtmlForm form1;
		protected TextBox txtKeywords;
		protected Button btnSearch;
		protected LinkButton lbtnUnLock;
		protected LinkButton btnDelete;
		protected Repeater rptList;
		protected HtmlGenericControl PageContent;
		protected TextBox txtPageNum;
		protected int totalCount;
		protected int page;
		protected int pageSize;
		protected string keywords = "";
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!string.IsNullOrEmpty(base.Request.Params["keywords"]))
			{
				this.keywords = base.Request.Params["keywords"].Trim();
			}
			this.pageSize = this.GetPageSize(15);
			if (!this.Page.IsPostBack)
			{
				this.RptBind("id>0" + this.CombSqlTxt(this.keywords), "is_lock desc,add_time desc");
			}
		}
		private void RptBind(string _strWhere, string _orderby)
		{
			if (!int.TryParse(base.Request.QueryString["page"], out this.page))
			{
				this.page = 1;
			}
			this.txtKeywords.Text = this.keywords;
			AjeeleeCms.Web.Plugin.Feedback.BLL.feedback feedback = new AjeeleeCms.Web.Plugin.Feedback.BLL.feedback();
			this.rptList.DataSource = feedback.GetList(this.pageSize, this.page, _strWhere, _orderby, out this.totalCount);
			this.rptList.DataBind();
			this.txtPageNum.Text = this.pageSize.ToString();
			string text = Utils.CombUrlTxt("index.aspx", "keywords={0}&page={1}", new string[]
			{
				this.keywords, 
				"__id__"
			});
			this.PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, text, 8);
		}
		protected string CombSqlTxt(string _keywords)
		{
			StringBuilder stringBuilder = new StringBuilder();
			_keywords = _keywords.Replace("'", "");
			if (!string.IsNullOrEmpty(_keywords))
			{
				stringBuilder.Append(string.Concat(new string[]
				{
					" and (title like '%", 
					_keywords, 
					"%' or user_name like '%", 
					_keywords, 
					"%')"
				}));
			}
			return stringBuilder.ToString();
		}
		private int GetPageSize(int _default_size)
		{
			int num;
			int result;
			if (int.TryParse(Utils.GetCookie("feedback_page_size"), out num))
			{
				if (num > 0)
				{
					result = num;
					return result;
				}
			}
			result = _default_size;
			return result;
		}
		protected void btnSearch_Click(object sender, EventArgs e)
		{
			base.Response.Redirect(Utils.CombUrlTxt("index.aspx", "keywords={0}", new string[]
			{
				this.txtKeywords.Text
			}));
		}
		protected void txtPageNum_TextChanged(object sender, EventArgs e)
		{
			int num;
			if (int.TryParse(this.txtPageNum.Text.Trim(), out num))
			{
				if (num > 0)
				{
					Utils.WriteCookie("feedback_page_size", num.ToString(), 43200);
				}
			}
			base.Response.Redirect(Utils.CombUrlTxt("index.aspx", "keywords={0}", new string[]
			{
				this.keywords
			}));
		}
		protected void lbtnUnLock_Click(object sender, EventArgs e)
		{
			AjeeleeCms.Web.Plugin.Feedback.BLL.feedback feedback = new AjeeleeCms.Web.Plugin.Feedback.BLL.feedback();
			for (int i = 0; i < this.rptList.Items.Count; i++)
			{
				int id = Convert.ToInt32(((HiddenField)this.rptList.Items[i].FindControl("hidId")).Value);
				CheckBox checkBox = (CheckBox)this.rptList.Items[i].FindControl("chkId");
				if (checkBox.Checked)
				{
					feedback.UpdateField(id, "is_lock=0");
				}
			}
			base.JscriptMsg("批量审核成功啦！", Utils.CombUrlTxt("index.aspx", "keywords={0}", new string[]
			{
				this.keywords
			}), "Success");
		}
		protected void btnDelete_Click(object sender, EventArgs e)
		{
			AjeeleeCms.Web.Plugin.Feedback.BLL.feedback feedback = new AjeeleeCms.Web.Plugin.Feedback.BLL.feedback();
			for (int i = 0; i < this.rptList.Items.Count; i++)
			{
				int id = Convert.ToInt32(((HiddenField)this.rptList.Items[i].FindControl("hidId")).Value);
				CheckBox checkBox = (CheckBox)this.rptList.Items[i].FindControl("chkId");
				if (checkBox.Checked)
				{
					feedback.Delete(id);
				}
			}
			base.JscriptMsg("批量删除成功啦！", Utils.CombUrlTxt("index.aspx", "keywords={0}", new string[]
			{
				this.keywords
			}), "Success");
		}
	}
}
